v = input()
m = 0

if len(v) == 4:
    for z in range(0,len(v)):
        for f in range(z + 1,len(v) + 1):
            y = int(v[z:f])
            b = 0
            for i in range(1,y + 1):
                if y % i == 0:
                    b = b + 1
            if b == 2:
                m = max(m,y)

print(m)